﻿<Page xmlns:Controls="using:Demo05.Controls" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Demo05"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ViewModels="using:Demo05.ViewModels"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    x:Class="Demo05.MainPage"
    mc:Ignorable="d">
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Refresh" Label="Refresh">
                <Interactivity:Interaction.Behaviors>
                    <Core:EventTriggerBehavior EventName="Click">
                        <Core:CallMethodAction MethodName="LoadData" TargetObject="{Binding Mode=OneWay}"/>
                    </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>

    <Page.DataContext>
        <ViewModels:MainPageViewModel/>
    </Page.DataContext>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <!-- left -->
        <ListBox ItemsSource="{Binding Items}"
                 ItemTemplate="{StaticResource TextTemplate}"
                 SelectedItem="{Binding Selected, Mode=TwoWay}"
                 Width="500" Height="500" Grid.Column="0" />

        <!-- middle -->
        <Grid Grid.Column="1" Background="DimGray" DataContext="{Binding Selected}">
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30" Margin="50">
                <Run Text="Vehicle:" />
                <Run Text="{Binding Text}" />
            </TextBlock>
        </Grid>

        <!-- right -->
        <Grid Grid.Column="2" Width="500" Height="500">

            <Controls:ListBoxMap SelectedItem="{Binding Selected, Mode=TwoWay}" ItemsSource="{Binding Items}">

                <Controls:ListBoxMap.Background>
                    <ImageBrush ImageSource="ms-appx:///Images/Background.jpg" Stretch="UniformToFill" Opacity=".75" />
                </Controls:ListBoxMap.Background>

                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <!--<ItemsControl.ItemTemplate>
                    <Binding Source="{StaticResource TruckTemplate}" />
                </ItemsControl.ItemTemplate>-->

                <ItemsControl.ItemTemplateSelector>
                    <Controls:MapSelector 
                        CarTemplate="{StaticResource CarTemplate}"
                        TruckTemplate="{StaticResource TruckTemplate}" />
                </ItemsControl.ItemTemplateSelector>

            </Controls:ListBoxMap>

        </Grid>

    </Grid>
</Page>
